
package nc.impl.pu.pu_order.pu_ordermaster;

import java.util.Arrays;

import org.apache.commons.lang3.ArrayUtils;

import nc.bs.framework.common.NCLocator;
import nc.vo.pub.BusinessException;
import nc.vo.pub.CircularlyAccessibleValueObject;
import nc.vo.pub.SuperVO;
import nc.vo.pub.ISuperVO;
import nc.vo.pub.IVOMeta;
import nc.vo.pub.VOStatus;
import nc.vo.pubapp.pattern.model.meta.entity.bill.IBillMeta;
import nc.vo.trade.pub.HYBillVO;
import nc.vo.pubapp.pattern.model.entity.bill.AbstractBill;
import nccloud.bs.excel.IXChangeContext;
import nccloud.bs.excel.plugin.AbstractImportProceeWithContext;
import nc.vo.order.pu_order.Pu_orderBody;
import nc.vo.order.pu_order.Pu_orderMasterVO;
import nc.vo.order.pu_order.AggPu_orderMasterVO;
import nc.itf.pu.pu_order.pu_ordermaster.IPu_orderMasterVOService;

public class AggPu_orderMasterVOImportProcess extends AbstractImportProceeWithContext {
	
	@Override
	protected void processBillWithContext(Object vo, IXChangeContext changcontext) throws BusinessException {
		AggPu_orderMasterVO targetVO = (AggPu_orderMasterVO)vo;
		targetVO.getParentVO().setStatus(VOStatus.NEW);

		Pu_orderBody[] pu_orderBodys = (Pu_orderBody[])targetVO.getChildren(Pu_orderBody.class);
		if(pu_orderBodys!=null && pu_orderBodys.length>0){
			Arrays.stream(pu_orderBodys).forEach(subvo->{
				subvo.setStatus(VOStatus.NEW);
			});
		}
  		getService().initDefaultData(targetVO.getParentVO());
		getService().saveAggPu_orderMasterVO(targetVO);
	}
	
	private IPu_orderMasterVOService getService() {
		return NCLocator.getInstance().lookup(IPu_orderMasterVOService.class);
	}

}
